// @algorithm @lc id=121 lang=cpp 
// @title best-time-to-buy-and-sell-stock


// @test([7,1,5,3,6,4])=5
// @test([7,6,4,3,1])=0
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        auto everLow = INT_MAX, earn = 0;
        for(auto & p : prices){
            if(p < everLow)
                everLow = p;
            else if(earn < p - everLow)
                earn = p - everLow;
        }
        return earn;
    }
};